/***************************************** 
 * Desc: UGUI框架的MonoBehaviour, 使用UGUIView框架时若要自己声明MonoBehaviour且与UGUIView类同一对象请继承该类
 * @Author: GSan
 * @Email: 2087653648@qq.com
 * CreateDate: 2020-07-27 16:50:20
*****************************************/

using UnityEngine;

namespace Common.UGUI.Base {

	[RequireComponent(typeof(RectTransform))]
	[RequireComponent(typeof(UGUIView))]
	public class UGUIMonoBehaviour<T> : MonoBehaviour where T : UGUIView, new() {

        public T UGUIView {

			get {

				if(_uguiView == null) {

					if (gameObject != null) {

						_uguiView = gameObject.GetComponent<T>();

						if (_uguiView == null) {

							Debug.LogError("UGUIMonoBehaviour name " + name + " has no UGUIView " + typeof(T).Name + " at the same gameObject.");
						}
					}
				}

				return _uguiView;
			}
			set {
				_uguiView = null;
			}
		}

		private T _uguiView;
	}
}
